@(users: com.avaje.ebean.Page[User], currentSortBy: String, currentOrder: String, currentFilter: String)

@link(newPage:Int, newSortBy:String) = @{
    
    var sortBy = currentSortBy
    var order = currentOrder
    
    if(newSortBy != null) {
        sortBy = newSortBy
        if(currentSortBy == newSortBy) {
            if(currentOrder == "asc") {
                order = "desc"
            } else {
                order = "asc"
            }
        } else {
            order = "asc"
        }
    }
    
    // Generate the link
    routes.Admin.user(newPage, sortBy, order, currentFilter)
    
}

@header(key:String, title:String) = {
    <th class="@key.replace(".","_") header @if(currentSortBy == key) @{if(currentOrder == "asc") "headerSortDown" else "headerSortUp"}">
        <a href="@link(0, key)">@title</a>
    </th>
}

    <div id="actions">
        
        <form action="@link(0, "name")" method="GET">
            <input type="search" id="searchbox" name="f" value="@currentFilter" placeholder="Filter by computer name...">
            <input type="submit" id="searchsubmit" value="Filter by name" class="btn primary">
        </form>
        
    </div>

	@if(users.getTotalRowCount == 0) {
        
        <div class="well">
            <em>Nothing to display</em>
        </div>
        
    } else {
        
        <table class="computers zebra-striped">
            <thead>
                <tr>
                    @header("username", "Username")
                    @header("name", "Name")
                    @header("surname", "Surname")
                    @header("email", "Email")
                </tr>
            </thead>
            <tbody>

                @for(user <- users.getList) {
                    <tr>
                        <td><a href="">@user.username</a></td>
                        <td>
                        	@user.name
                        </td>
                        <td>
                        	@user.surname
                        </td>
                        <td>
                            @user.email
                        </td>
                        <td>
                        	<a href="@routes.Admin.deleteUser(user.id)">Delete</a>
                        </td>
                    </tr>
                }

            </tbody>
        </table>

        <div id="pagination" class="pagination">
            <ul>
                @if(users.hasPrev) {
                    <li class="prev">
                        <a href="@link(users.getPageIndex - 1, null)">&larr; Previous</a>
                    </li>
                } else {
                    <li class="prev disabled">
                        <a>&larr; Previous</a>
                    </li>
                }
            	@for(i <- 0 until users.getTotalPageCount()){
            		<li><a href = "@link(i,null)">@(i+1)</a></li>
            	}
                @if(users.hasNext) {
                    <li class="next">
                        <a href="@link(users.getPageIndex + 1, null)">Next &rarr;</a>
                    </li>
                } else {
                    <li class="next disabled">
                        <a>Next &rarr;</a>
                    </li>
                }
            </ul>
        </div>
}